package jxl.common.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Slf4jLogger extends jxl.common.Logger {

	/**
	 * The slf4j logger
	 */
	private Logger logger;

	public Slf4jLogger() {
		super();
	}

	private Slf4jLogger(Logger logger) {
		super();
		this.logger = logger;
	}

	@Override
	public void debug(Object message) {
		logger.debug(convertToString(message));
	}

	@Override
	public void debug(Object message, Throwable t) {
		logger.debug(convertToString(message), t);
	}

	@Override
	public void error(Object message) {
		logger.error(convertToString(message));
	}

	@Override
	public void error(Object message, Throwable t) {
		logger.error(convertToString(message), t);
	}

	@Override
	public void fatal(Object message) {
		logger.error(convertToString(message));
	}

	@Override
	public void fatal(Object message, Throwable t) {
		logger.error(convertToString(message), t);
	}

	@Override
	public void info(Object message) {
		logger.info(convertToString(message));
	}

	@Override
	public void info(Object message, Throwable t) {
		logger.info(convertToString(message), t);
	}

	@Override
	public void warn(Object message) {
		logger.warn(convertToString(message));
	}

	@Override
	public void warn(Object message, Throwable t) {
		logger.warn(convertToString(message), t);
	}

	@Override
	protected jxl.common.Logger getLoggerImpl(Class cl) {
		logger = LoggerFactory.getLogger(cl);
		return new Slf4jLogger(logger);
	}

	protected final String convertToString(Object message) {
		if (message == null) {
			return (String) message;
		} else {
			return message.toString();
		}
	}

}
